<template>
	<view class="container">
		<u-navbar :background="{ background: '#6EC9E1' }" :is-fixed="true" :z-index='999' :border-bottom="false"
			back-icon-color="#FFF">
		</u-navbar>

		<view class="main">
			<view class="title">
				<text>预览</text>
			</view>
			<view class="card">
				<view class="left">
					<u-avatar :size='96' bg-color='#eee' mode="square" :src="doctor_info.avatar"></u-avatar>
					<view class="docker">
						<p>{{doctor_info.username }}</p>
						<view class="member">
							<span class="icn"></span>
							<span>{{member_info.username||''}}</span>
							<span>{{member_info.gender_text||''}}</span>
							<span>{{member_info.age||''}}</span>
						</view>

					</view>
				</view>
				<view class="right">
					<u-icon name="arrow-right" color="#3e3e3e" size="24"></u-icon>
				</view>
			</view>


			<view class="content">
				<!-- 综合 -->
				<view class="card from">
					<view class="z-s">
						<p class="label">一般项目</p>
						<view class="item">
							{{member_info.username?member_info.username+'，':''}}
							{{member_info.gender_text?member_info.gender_text+'，':''}}
							{{member_info.age?member_info.age+'，':''}}
							{{member_info.height?member_info.height+'cm，':''}}
							{{member_info.weight?member_info.weight+'kg，':''}}
							{{member_info.bmi?'BMI'+member_info.bmi+',':''}}
							{{member_info.education_text||'-'}}
						</view>
					</view>
				</view>
				<view class="card from" v-if="type==2">
					<view class="z-s">
						<p class="label">基本信息</p>
						<view class="item">
							<view class="i-v" v-if="item.title" :class="item.type>2?'i-f':''"
								v-for="(item,index) in info.content[0].detail">
								<span class="label">{{num+index}}.{{item.title}}</span>
								{{item.value||''}}
							</view>
						</view>
					</view>
				</view>
				<view class="card from" v-if="type==2">
					<view class="z-s">
						<p class="label">现有问题</p>
						<view class="item">
							<view class="i-v" v-if="item.value" :class="item.type>2?'i-f':''"
								v-for="(item,index) in info.content[1].detail">
								<span class="label">{{num+index}}.{{item.title}}</span>
								{{item.value||''}}
								<view class="_img">
									<u-image @click="imagePrivew(src)" :width='120' :height='120' :border-radius='10'
										v-for="src in item.images" :src="src">
										<u-loading slot="loading"></u-loading>
										<view slot="error" style="font-size: 24rpx;">加载失败</view>
									</u-image>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="card from" v-if="type==2">
					<view class="z-s">
						<p class="label">既往问题</p>
						<view class="item">
							<view class="i-v" v-if="item.value" :class="item.type>2?'i-f':''"
								v-for="(item,index) in info.content[2].detail">
								<span class="label">{{num+index}}.{{item.title}}</span>
								{{item.value||''}}
								<view class="_img">
									<u-image @click="imagePrivew(src)" :width='120' :height='120' :border-radius='10'
										v-for="src in item.images" :src="src">
										<u-loading slot="loading"></u-loading>
										<view slot="error" style="font-size: 24rpx;">加载失败</view>
									</u-image>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="card from" v-if="type==1">
					<view class="z-s">
						<view>
							<view class="i-v" v-if="item.value" :class="item.type>2?'i-f':''"
								v-for="(item,index) in info.content">
								<span class="label">{{num+index}}.{{item.title}}</span>
								{{item.value}}
								<view class="_img">
									<u-image @click="imagePrivew(src)" :width='120' :height='120' :border-radius='10'
										v-for="src in item.images" :src="src">
										<u-loading slot="loading"></u-loading>
										<view slot="error" style="font-size: 24rpx;">加载失败</view>
									</u-image>
								</view>
							</view>
						</view>
					</view>
				</view>


			</view>

			<view class="btn" @click="modal=true">提交</view>
		</view>
		<u-toast ref="uToast" />
		<u-modal v-model="modal" content="是否提交" @confirm="save" :show-cancel-button='true'
			:mask-close-able="true"></u-modal>
	</view>
</template>

<script>
	import {
		addAdvice,
		chat,
		getDoctorInfo,
		memberDetail
	} from '@/api/index.js'
	export default {
		data() {
			return {
				info: {},
				user: {},
				show: false,
				num: 1,
				doctor_info: '',
				member_info: '',
				type: '',
				modal: false
			}
		},

		onLoad(e) {
			this.type = e.type
			// 咨询问卷页面blur事件在提交事件后执行处理
			this.$store.watch((state, getters) => {
				return state.zixunPreview
			}, (value) => {
				console.log(value, 'the')
			})
			// -------------------------------------------
			this.init()
		},
		methods: {
			init() {
				this.user = this.ws.getUserInfo()
				if (this.user.job == 1) {
					this.show = true
				}

				// 拷贝 不能影响问卷
				this.info = JSON.stringify(this.$store.state.zixunPreview)
				this.info = JSON.parse(this.info)
				this.info.content.forEach(item => {
					item.detail.forEach(itm => {
						if (itm.images) {
							if (itm.images.indexOf(',') != -1) {
								itm.images = itm.images.split(',')
							} else {
								itm.images = [itm.images]
							}
						}
					})
				})
				// console.log(this.info,'问卷');
				if (this.type == 1) {
					this.info.content = this.info.content[0].detail
					// console.log(this.info,'简单问卷');
				}
				getDoctorInfo({
					'doctor_id': this.info.doctor_id
				}).then(res => {
					if (res.code == 1) {
						this.doctor_info = res.data.info
					}
				})
				memberDetail({
					'id': this.info.member_id
				}).then(res => {
					if (res && res.code == 1) {
						this.member_info = res.data.detail;
					}
				})

			},
			save() {
				let that = this
				let data = JSON.stringify(this.$store.state.zixunPreview)
				data = JSON.parse(data)
				if (that.type == 1) {
					data.content = data.content[0].detail
				}
				addAdvice(data).then(res => {
					if (res.code == 1) {
						that.$refs.uToast.show({
							title: res.msg,
							type: 'primary',
						})

						uni.redirectTo({
							url: '/sub/session-info/session-info?id=' + res.data.session_id
						})

					} else {
						that.$refs.uToast.show({
							title: res.msg
						})
					}
				})
			},
			goTo(url) {
				uni.navigateTo({
					url: url
				})
			},
			tochat(id) {
				let that = this
				chat({
					'user_id': id
				}).then(res => {
					if (res.code == 1) {
						that.ws.tochat(res.data.session_id)
					}
				})
			},
			imagePrivew(src) {
				uni.previewImage({
					urls: [src],
				})
			},
			medication(e) {
				let obj = {
					"drug_id": e.id,
					"title": e.title
				}

				this.form.drug.push(obj)
				this.$forceUpdate()
			},




		}

	}
</script>

<style lang="less">
	.container {
		background: url('@/static/img/mine/header-bg.png');
		background-size: 100% 30vh;
		background-repeat: no-repeat;
		background-color: #EEE;
		min-height: 100vh;
		position: relative;
		line-height: 25px;
		padding: 30rpx;

		u-form {
			width: 100%;

		}

		.main {
			padding-bottom: 80px;

			.fts2 {
				font-size: 13px;
				opacity: 0.8;
			}

			.docker {
				margin-left: 16rpx;
			}

			.left {
				display: flex;
				align-items: center;

				.member {
					display: flex;
					align-items: center;
					opacity: 0.7;
					font-size: 13px;

					span {
						margin-right: 20rpx;
					}

					.icn {
						display: block;
						background-color: #4b4b4b;
						border-radius: 50%;
						height: 10rpx;
						width: 10rpx;
					}
				}
			}

			.title {
				color: #FFF;
				text-align: center;

				text {
					font-size: 24px;
				}

				view {
					margin-top: 10rpx;
					margin-bottom: 30px;
				}

			}


			.questionnaire {
				display: block !important;

				text {
					font-weight: bold;
					font-size: 18px;
				}

				view {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 30rpx;
					opacity: 0.6;
				}
			}

			.label {
				font-size: 13px;
				color: #6EC9E1;
			}

			.yijian {
				display: block !important;
				margin-top: 20rpx !important;
				width: 100%;

				.content {
					width: 100%;
					padding: 0 20rpx;

					span {
						display: inline-block;
						min-width: 50%;
						margin-top: 20rpx;
					}

					p {
						font-size: 14px;
						margin: 20rpx 0;
						color: #B2B2B2;
					}

					text {
						color: #666666;
					}

					image {
						height: 16px;
						width: 16px;
					}

					.c-i {
						display: flex;
						justify-content: space-between;
						align-items: center;
					}
				}
			}

			.from {
				padding: 0 30rpx !important;

				.item {
					width: 100%;
					margin-top: 20rpx;
					padding: 20rpx 0;
					border-top: 0.5rpx solid rgba(200, 200, 200, 0.2);
					font-size: 13px;
					font-weight: 550;
				}

				.z-s {
					padding: 20rpx 0;
					width: 100%;
				}

				.i-v {
					display: flex;
					align-items: center;
					flex-wrap: wrap;
					width: 100%;
					line-height: 30px;

					span {
						margin-right: 20rpx;
						min-width: 60px;
						color: #999999;
						font-weight: 500 !important;
						width: auto;
					}

				}

				.i-f {
					flex-flow: column;
					align-items: flex-start;
				}
			}

			.card {
				margin-top: 30rpx;
				background-color: #FFF;
				border-radius: 16rpx;
				padding: 30rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}

			.notinfo {
				height: 100px;
				text-align: center;
				line-height: 100px;
			}


		}

		._img {
			display: flex;
			align-items: center;
			flex-wrap: wrap;

			u-image {
				margin-right: 20rpx;
				margin-bottom: 16rpx;
				border-radius: 4px;
				border: 0.5rpx rgba(200, 200, 200, 0.2) solid;
			}
		}
	}
</style>